import { message } from "antd";
import copy from "copy-to-clipboard";

export function copyCode(event: React.MouseEvent, code: string) {
    event.stopPropagation();
    copy(code);
    message.success('成功复制到剪切板');
}

// 字符串下划线转驼峰
export const formatToHump = (value: string, needUp: boolean = false) => {
    let str = value.replace(/_([a-z])/g, function (match, letter) {
        return letter.toUpperCase();
    });
    if (needUp) {
        str = str.slice(0, 1).toUpperCase() + str.slice(1);
    }
    return str;
}

// 字符串驼峰转下划线
export const formatToLine = (value: string) => {
    let str = value.slice(0, 1).toLowerCase() + value.slice(1);
    return str.replace(/([A-Z])/g, '_$1').toLowerCase()
}